package com.chen.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chen.entity.HomeAdvertise;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chen.entity.HomeNewProduct;
import com.chen.entity.HomeRecommendProduct;
import com.chen.entity.Product;
import com.chen.mapper.HomeAdvertiseMapper;
import com.chen.mapper.HomeNewProductMapper;
import com.chen.mapper.HomeRecommendProductMapper;
import com.chen.service.HomeAdvertiseService;
import com.chen.vo.HomeAdvertiseVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 首页轮播广告表 服务实现类
 * </p>
 *
 * @author cws
 * @since 2024-11-22
 */
@Service
public class HomeAdvertiseServiceImpl extends ServiceImpl<HomeAdvertiseMapper, HomeAdvertise> implements HomeAdvertiseService {


    @Resource
    HomeAdvertiseMapper homeAdvertiseMapper;

    @Resource
    HomeNewProductMapper homeNewProductMapper;

    @Resource
    HomeRecommendProductMapper homeRecommendProductMapper;


    @Override
    public HomeAdvertiseVo homeAdvertiseAndNewProductAndHotProduct() {
        List<HomeAdvertise> homeAdvertises = homeAdvertiseMapper.selectList(null);
        HomeAdvertiseVo homeAdvertiseVo = new HomeAdvertiseVo();
        homeAdvertiseVo.setHomeAdvertise(homeAdvertises);
        Integer count = homeNewProductMapper.selectCount(new LambdaQueryWrapper<HomeNewProduct>().eq(HomeNewProduct::getRecommendStatus, 1));
        if (count > 0) {
            Product homeNewProduct = homeNewProductMapper.selectNewProduct();
            homeAdvertiseVo.setHomeNewProduct(homeNewProduct);
        }
        Integer count1 = homeRecommendProductMapper.selectCount(new LambdaQueryWrapper<HomeRecommendProduct>().eq(HomeRecommendProduct::getRecommendStatus, 1));
        if (count1 > 0) {
           Product homeHotProduct = homeRecommendProductMapper.selectHotProduct();
           homeAdvertiseVo.setHomeRecommendProduct(homeHotProduct);
        }
        return homeAdvertiseVo;
    }
}
